home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / TAWUG / TAWUG Disk No. 56 (SHK) / TAWUG56.shk / PASCAL.DISKS (.txt) < prev    next >
AppleWorks Document  |  1987-07-01  |  8KB  |  130 lines

  1. O=====|====|====|====|====|====|====|====|====|====|====|====|====|====|====|===
  2. PASCAL - THE CASE OF THE BLOWN DISK
  3. by Jim Wrenholt
  4. Reprinted from The Scarlett Letter'
  5. Published by the Big Apple User Group
  6. H     I've been spending my spare time lately learning my way around the P
  7. NPascal system on my Apple.  After reading through an introductory book on the O
  8. Msubject, I thought myself ready to study some actual Pascal programs.  Well, L
  9. Jafter five minutes of fiddling around I succeeded only in obliterating my N
  10. Ldisk's directory.  I still don't know what magical set of keystrokes causes 
  11. the disaster.
  12. L     Being a veteran of such DOS catastrophies, my first thought was to get J
  13. Hout my Disk ZAP and fix the disk. Pascal lives on the disk in 16 sector P
  14. Nformat so that my ZAP (track/sector read/write routine) is capable of reading G
  15. Eit. After spending a little time looking, I became convinced that my O
  16. Mprogram's textfiles were still intact and that only the directory was messed 
  17. L     Now to rebuild the directory. First I needed to discover the layout of P
  18. Nthe directory.  Pascal is not DOS and the Pascal referance manuals are not as P
  19. Ncomplete as the DOS manuel either.  So scrounging through my old magazines, I O
  20. Mturned up an article in CALL APPLE from March/April 1981 that showed how the '
  21. directory is formatted on the disk.  
  22. N     All that is needed is a name and the beginning and ending block number.  N
  23. LPascal numbers are stored in consecutive blocks so there is no track/sector K
  24. Ilist to locate.  But since Disk ZAP deals in tracks and sectors the real I
  25. Gchallenge became to discover how the block numbers are mapped onto the O
  26. track/sectors.  The results of my sleuthing are shown in the following table.
  27. BLOCK #     FIRST         SECOND%
  28.          TRACK/SECTOR  TRACK/SECTOR
  29. x0           y/O           y/E 
  30. x1           y/D           y/C 
  31. x2           y/B           y/A 
  32. x3           y/9           y/8 
  33. x4           y/7           y/6 
  34. x5           y/5           y/4 
  35. x6           y/3           y/2 
  36. x7           y/1           y/F
  37. x8           z/O           z/E 
  38. x9           z/D           z/C 
  39. xA           z/B           z/A 
  40. xB           z/9           z/8 
  41. xC           z/7           z/6
  42. xD           z/5           z/4 
  43. xE           z/3           z/2 
  44. xF           z/1           z/F
  45. Where y = 2 * x  and z = 2 * x + 1
  46. K     It turns out that this block number to track/sector mapping is rather =
  47. twisted.  Remember that it takes two sectors for one block.
  48. L     To convert from block number to track/sector you must think in hex, or N
  49. Lat least convert.  For instance, to find block number $53 on the disk, find O
  50. MX3 in the first column.  Then  X is $5 in our case.  Now double X to get Y,  P
  51. NY = 2 * X = 2 * $5 = $A.  Finally, the next two columns give the track/sector P
  52. Npair, Y/9 and Y/8. In our example Y = $A, so sectors 9 and  8 on track $A are 
  53. the desired locations.
  54. J     As another example, let's locate block $3C.  First, locate XC in the M
  55. Kfirst column. Using the formula, X = 2 * 3 +1 = 7 so the block is found on 
  56. sectors 7 and 6 of track 7.
  57. N     To go the other way you must decide if the track is even or odd.  If the M
  58. track is even, use the top half of the chart; if odd, use the bottom half. 
  59. C     For an example of this, let's find the block corresponding to P
  60. Ntrack/sector $OC/$OF.  First $OC is an even number so use the top half of the P
  61. Ntable.  Next X = $OC/2 = $6.  Locating Y/F in the top half and moving over to O
  62. Mthe first column shows that track/sector $OC/$OF is the second half of block 
  63. number $67.
  64. N    There is just one more thing to be remembered. When you find the start of N
  65. Lyour actual text on the disk you need to back up 2 blocks to leave room for P
  66. Nthe header which is at the start of all text files.  For more information see E
  67. the Apple Pascal Reference Manual 3.2.1.  The Format of Text Files.
  68. L    Now to rebuild the directory.  First make a backup of your disk.  I use P
  69. NCOPYA from the DOS System Master for this.  Of course, if I would have backed O
  70. Mup in the very beginning I would not have had to go through all of this, but I
  71. Gthat's hindsight.  Any direction modification of sectors is considered /
  72. dangerous so we need to back up now for sure.
  73. L    The Pascal disk directory is divided into entries that are 26 (decimal) F
  74. Dbytes long.  The first 26 bytes are for the disk volume name.  Each P
  75. Nsubsequent group of 26 bytes is for an individual file.  The directory starts P
  76. Non track $O, sector $B and extends downward.  There is room for up to 77 file 
  77. names.
  78. THE FIRST 26 BYTES
  79. BYTE *
  80. 1,0   START OF DIRECTORY$
  81. 3,2   END OF DIRECTORY BLOCKNUMBER
  82. 5,4   ALWAYS ZERO"
  83. 6     LENGTH OF DISK VOLUME NAME
  84. 7-13  DISK VOLUME NAME STRING 
  85. 15,14 NUMBER OF BLOCKS ON DISK 
  86. 17,16 ENTRIES IN THE DIRECTORY
  87. 19,18 ALWAYS ZERO
  88. 21,20 CURRENT DATE
  89. 23,22 ALWAYS ZERO
  90. 25,26 ALWAYS ZERO
  91. INDIVIDUAL FILES
  92. BYTE *
  93. 1,0   BLOCK START NUMBER
  94. 3,2   BLOCK END NUMBER
  95. 5,4   FILE TYPE:
  96.       2=CODE, 3=TEXT, 5=DATA
  97. 6     LENGTH OF FILE NAME
  98. 7-21  FILENAME STRING%
  99. 23,22 NUMBER OF BYTES IN LAST BLOCK
  100. 25,24 FILE DATE
  101. K     As an example, I have included a sector dump of my Apple 1 diskette.  O
  102. MNotice, as usual, the low order byte is first.  Also the ending block number O
  103. Mis really the beginning of the next file or one block past the actual end of 
  104. the text file.
  105. N     Let's look at the initial 26 bytes first.  The start of the directory is N
  106. L0000, or block zero.  The end of the directory is 0600, or block six.  Next Q
  107. Owe find two bytes of filler, 00 00.  Now 06 is the length of the volume name.  0
  108. The volume name itself appears as shown below.
  109.    41  50  50  4C  45  31
  110.    A   P   P   L   E   1
  111. K     Next comes three more filler bytes 00 18 01, followed by a 0A00 which P
  112. Nshows that there are 10 file entries in my current directory.  Two more bytes N
  113. Lof filler, 00 00 are followed by the current date in Pascal format, 2C A5.  '
  114. The next four bytes are again filler.
  115. M     The first individual file is my SYSTEM.APPLE is broken down like this.  G
  116. EThe starting block number is six, 06 00.  The ending block number is L
  117. Jthirty-eight or hex $26, 26 00.  The file type is 05 00 which indicates a P
  118. Ndata file.  The length of the data file is twelve, $0C.  The file name string 
  119. 53 59 53 54 45 4D 2E 41 50 50 4C 45$
  120. S  Y  S  T  E  M  .  A  P  P  L  E
  121. H     There are a remaining three bytes of filler 00 24 67.  The maximum L
  122. Jlength for a file name is fifteen bytes.  The number of bytes in the last H
  123. Fblock is 00 02, which says all the bytes in the last block are used.  O
  124. MRemember 00 02 is low order byte first, so it stands for 2 * 256 = 512 bytes P
  125. Nwhich is a full block.  This was the case for all the text files I have dealt >
  126. with.  Finally there are two bytes for the file date, 9B A0.
  127. L     These examples will serve as an entrance into the understanding of how M
  128. KPascal formats information in track/sector blocks.  Back up your disks and ;
  129. you will need not to use this information in desperation.
  130.